package com.disapand.dingdang.configuration

import org.hibernate.validator.HibernateValidator
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import javax.validation.Validation
import javax.validation.Validator

/**
 * @author disapand
 * @date 2022/2/27 - 16:30 星期日
 */
@Configuration
class ValidationConfiguration {

    /**
     * 设置 validation 为 fast fail 模式，即有一条验证失败立即返回
     *
     * @return
     */
    @Bean
    fun validator(): Validator? {
        val provider = Validation.byProvider(HibernateValidator::class.java)
            .configure()
            .failFast(true)
            .buildValidatorFactory()
        return provider.validator
    }
}